<!DOCTYPE html>
<html>
<head>
    <title>我的消息 - {$site_info.site_name|default=''}</title>
    <meta name="keywords" content="" />
    <meta name="description" content="">
    <include file="public@head"/>
</head>
<body class="body-white" >
<include file="public@nav" />


<div class="container tc-main">
    <div class="row">
        <div class="col-md-3">
            <include file="public@jiaxiaonav" />
        </div>

        <div class="col-md-9 ">
            <!--标题-->
            <div class="personal-nav" style="border:none;">
                <h2>我的消息</h2>
                <!--nav-->
                <ul class="nav nav-tabs" style="margin-bottom: 40px;">
                    <php>if($msg_status == -1){ echo '<li class="active">'; }else{ echo '<li>'; }</php><a href="{:url('user/FrontMessage/index',array('status'=>-1))}">全部</a></li>
                    <php>if($msg_status == 0){ echo '<li class="active">'; }else{ echo '<li>'; }</php><a href="{:url('user/FrontMessage/index',array('status'=>0))}">未读</a></li>
                    <php>if($msg_status == 1){ echo '<li class="active">'; }else{ echo '<li>'; }</php><a href="{:url('user/FrontMessage/index',array('status'=>1))}">已读</a></li>
                </ul>
            </div>
            <!--标题end-->
            <div class="clear"></div>

            <div class="personal-mymessage ">
                <ul>
                    <if condition="count($messages) eq 0">
                        您还没有消息
                    <else/>
                        <li>
                            <div>
                                <input type="checkbox" id='selectAll'>
                                <a href="javascript:;" id="handle_msg" class="btncss">标记为已读</a>
                                <a href="javascript:;" id="delete_msg" class="btncss">删除所选</a>
                            </div>
                        </li>
                        <foreach name="messages" item="vo">
                            <if condition="$vo.dtime eq 0">
                                <if condition="$vo.msg_status==0">
                                    <li class='not_read'>
                                        <div>
                                        <span>
                                            <input type="checkbox" name="ids[]" value="{$vo.mu_id}" title="{$vo.mu_id}">
                                            <h3>
                                                <i class="fa fa-envelope-o fa-fw"></i>{$vo.subject|default=''}
                                            </h3>
                                        </span>
                                            <span class="pull-right">{$vo.create_time|date="Y年n月j日 G时i分",###}</span>
                                        </div>
                                        <div style="display:none;">{$vo.content|default=''}</div>
                                        <!--<div>{:get_substring($vo.content,30)}</div>-->
                                    </li>
                                    <else/>
                                    <li>
                                        <div>
                                       <span>
                                           <input type="checkbox" name="ids[]" value="{$vo.mu_id}" title="{$vo.mu_id}">
                                            <h3><i class="fa fa-envelope-open-o fa-fw"></i>{$vo.subject|default=''}</h3>
                                        </span>
                                            <span class="pull-right">{$vo.create_time|date="Y年n月j日 G时i分",###}</span>
                                        </div>
                                        <div>{$vo.content|default=''}</div>
                                        <!--<div>{:get_substring($vo.content,40)}</div>-->
                                    </li>
                                </if>
                            </if>
                        </foreach>
                    </if>
                </ul>
            </div>

        </div>
    </div>
</div>
<!-- /container -->

<include file="public@footer" />
<include file="public@scripts" />
<script>
    $(function () {
        $('#selectAll').change(function () {
            if ($(this).attr('checked')){
                $('input[type="checkbox"]').attr('checked',true);
            }else{
                $('input[type="checkbox"]').attr('checked',false);
            }
        })
    });

    //单击为已读
    $('.not_read').click(function () {
        var $this=$(this);
        var msg_user_id=$this.find('input').val();
        console.log(msg_user_id);
        $.ajax({
            url:"{:url('user/FrontMessage/ajaxStatus')}",
            type:'post',
            dataType:'json',
            data:{"ids":msg_user_id},
            success:function(jsonData){
                  $this.removeClass('not_read');
                  $this.find('div').show(500);
                  $this.find('i').addClass('fa-envelope-open-o');

//                layer.msg(jsonData.msg);
//                window.location.reload();
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
            }
        });
    })

    //标记已读
    $('#handle_msg').click(function () {
        var msg_user_id = '';
        $('input[name="ids[]"]:checked').each(function(){
            msg_user_id += ($(this).val())+',';
        });

        $.ajax({
            url:"{:url('user/FrontMessage/ajaxStatus')}",
            type:'post',
            dataType:'json',
            data:{"ids":msg_user_id},
            success:function(jsonData){
                layer.msg(jsonData.msg);
                window.location.reload();
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
            }
        });
    });

    //批量删除
    $('#delete_msg').click(function () {
        var msg_user_id = '';
        $('input[name="ids[]"]:checked').each(function(){
            msg_user_id += ($(this).val())+',';
        });

        $.ajax({
            url:"{:url('user/FrontMessage/delete')}",
            type:'post',
            dataType:'json',
            data:{"ids":msg_user_id},
            success:function(jsonData){
                layer.msg(jsonData.msg);
                window.location.reload();
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
            }
        });
    });
</script>
</body>
</html>